package com.api.shopapi.mapper;

import com.api.shopapi.entity.Seats;
import com.api.shopapi.entity.dto.SeatsDTO;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface SeatsMapper {

    @Insert("insert into seats (" +
            "SeatsCode," +
            "UserCode," +
            "Name," +
            "Phone," +
            "StaffCode," +
            "CallingPhone," +
            "GovernmentCode" +
            ") " +
            "values " +
            "(" +
            "#{seats.SeatsCode}," +
            "#{seats.UserCode}," +
            "#{seats.Name}," +
            "#{seats.Phone}," +
            "#{seats.StaffCode}," +
            "#{seats.CallingPhone}," +
            "#{seats.GovernmentCode}" +
            ")" )
    int insert(@Param("seats") Seats seats);


    @Delete("delete from seats where seatsCode=#{seatsCode}")
    int deleteBySeatsCode(@Param("seatsCode") String seatsCode);


    @Update("update seats set " +
            "UserCode=#{seats.UserCode}," +
            "GovernmentCode=#{seats.GovernmentCode}," +
            "Name=#{seats.Name}," +
            "Phone=#{seats.Phone}," +
            "StaffCode=#{seats.StaffCode}," +
            "CallingPhone=#{seats.CallingPhone}" +
            " where SeatsCode=#{seats.SeatsCode}")
    int update(@Param("seats") Seats seats);


    @Select("select * from seats where SeatsCode=#{seatsCode} limit 1")
    Seats getBySeatsCode(@Param("seatsCode") String seatsCode);

    @Select("select * from seats where Phone=#{phone} limit 1")
    Seats getByPhone(@Param("phone") String phone);

    @Select("select * from seats where UserCode=#{userCode} limit 1")
    Seats getByUserCode(@Param("userCode") String userCode);

    @Select("select * from seats where StaffCode=#{staffCode} limit 1")
    Seats getByStaffCode(@Param("staffCode") String staffCode);

    @Select("select * from seats where GovernmentCode=#{governmentCode} limit 1")
    Seats getByGovernmentCode(@Param("governmentCode") String governmentCode);


    @Select("select * from seats")
    List<Seats> getList();

    @Select("select s.*,g.Name GovernmentName from seats s,government g where g.GovernmentCode=s.GovernmentCode")
    List<SeatsDTO> getListAndGov();



}
